package day4;

import java.util.Scanner;

/**
 * 进制转换
 * 给定一个十进制数M，以及需要转换的进制数N。将十进制数M转化为N进制数
 */

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int m = scanner.nextInt();
        int n = scanner.nextInt();

//        int[] arr = new int[16];
//
//        int index = 0;
//        arr[index++] = 1;
//        int num = 0;
//        int b = 1;
//        while(num != m){
//            if (arr[index - 1] == 1){
//                arr[index] = 0;
//            }else if (arr[index - 1] == 0){
//                arr[index - 1] = 1;
//            }
//
//        }
//        arr.reverse();
//        for (int i = 0; i <= index; i++) {
//            System.out.print(arr[i]);
//        }
        System.out.println(slove(m, n).toCharArray());
    }

    private static String slove(int m, int n) {
        if (m == 0) {
            System.out.println(0);
        }
        int flag = 0;
        if (m < 0) {
            flag = -1;
            m = -m;
        }
        StringBuffer stringBuffer = new StringBuffer();
        while (m > 0) {
            int a = m % n;

            if (a >= 0 && a <= 9) {
                stringBuffer.append(a);
            }else {
                stringBuffer.append((char) ('A' + a - 10));
            }

            m = m / n;
        }
        if (flag == -1) {
            stringBuffer.append('-');
        }
        stringBuffer.reverse();
        return stringBuffer.toString();
    }
}

